package com.example.java_gobang.common;

import com.example.java_gobang.model.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionUtils {
    /**
     * 得到当前登录的用户
     */
    public static User getUser(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if (session != null &&
                session.getAttribute(AppVariable.USER_SESSION_KEY) != null){
            // 说明用户已登录
            return (User) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return null;
    }
}
